<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    
    <!-- 更宽松的CSP策略，允许加载外部SDK -->
    <meta http-equiv="Content-Security-Policy" 
          content="default-src 'self'; 
                   script-src 'self' 'unsafe-inline' 'unsafe-eval' https://hia.volcenginepaas.com chrome-extension://*; 
                   connect-src 'self' http://localhost:5001 ws://localhost:* wss: https://hia.volcenginepaas.com https://*.volcenginepaas.com;
                   style-src 'self' 'unsafe-inline' https://hia.volcenginepaas.com;
                   img-src 'self' data: https: blob:;
                   font-src 'self' data: https://hia.volcenginepaas.com;
                   frame-src 'self' https://hia.volcenginepaas.com;">
    
    <meta name="description" content="股票MACD和RSI技术分析工具" />
    
    <!-- 火山引擎Hiagent Web SDK -->
    <script src="https://hia.volcenginepaas.com/resources/product/llm/public/sdk/embedLite.js"></script>
    
    <title>股票技术分析系统</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    
    <!-- 初始化火山引擎Web SDK -->
    <script>
      // 确保SDK已加载后再初始化
      function initHiagentSDK() {
        const SDK_CONFIG = {
          appKey: "d3r44ffbn21kct1r88tg",
          baseUrl: "https://hia.volcenginepaas.com",
        };

        // 尝试获取SDK对象
        const SDK = window.HiagentWebSDK || window.VolcEngineEmbedSDK;
        
        if (SDK) {
          try {
            // 尝试 HiagentWebSDK.WebLiteClient
            if (SDK.WebLiteClient) {
              new SDK.WebLiteClient(SDK_CONFIG);
              console.log("✅ 火山引擎Web SDK (WebLiteClient) 初始化成功");
            }
            // 尝试 VolcEngineEmbedSDK.init
            else if (SDK.init) {
              SDK.init(SDK_CONFIG);
              console.log("✅ 火山引擎Web SDK (VolcEngineEmbedSDK) 初始化成功");
            }
          } catch (error) {
            console.error("❌ SDK初始化失败:", error);
          }
        } else {
          // 如果SDK还未加载，等待一段时间后重试
          setTimeout(initHiagentSDK, 1000);
        }
      }
      
      // 页面加载完成后初始化SDK
      if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initHiagentSDK);
      } else {
        initHiagentSDK();
      }
    </script>
  </body>
</html>